package auctionhaus



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions
 */
@TestFor(CustomerController)
@Mock([Customer,Listing,Bid])
class CustomerControllerTests {

    // test whether we can delete a customer WITHOUT a listing
    void testDeleteCustomerWithoutListing() {
        // create a customer without a listing
        Customer customerWithoutListing = new Customer(
                email: "janeDoe@acme.com",
                password: "1234567"
        )
        customerWithoutListing.save(flush:true)

        // execute a POST to delete the customer without a listing
        request.method = 'POST'
        params.id = customerWithoutListing.id
        controller.delete()

        // make sure we DON'T get the can't delete customer error message
        assert flash.message != "The customer must have 0 bids and 0 listings before they can be deleted."
    }

    // test whether we can delete a customer that has a listing
    void testDeleteCustomerWithListing() {
        // create a customer
        Customer customerWithListing = new Customer(
                email: "janeDoe@acme.com",
                password: "1234567"
        )
        customerWithListing.save(flush:true)

        // create a listing
        Listing listingForCustomer = new Listing(
                name: "My awesome pocket lint!",
                endTime: new Date() + 5,
                seller: customerWithListing,
                startBid: 1
        )
        listingForCustomer.save(flush:true)

        // execute a POST to delete the customer with a listing
        request.method = 'POST'
        params.id = customerWithListing.id
        controller.delete()

        // make sure we DO get the can't delete customer error message
        assert flash.message == "The customer must have 0 bids and 0 listings before they can be deleted."
    }
}
